package com.anysoft.me.callback;

import com.anysoft.base.BaseActivity;
import com.anysoft.view.dialog.LoadingDialog;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.request.base.Request;

/**
 * Created by lty on 2018/1/29.
 */

public abstract class StringDialogCallback extends StringCallback {

    private LoadingDialog loadingDialog;

    public StringDialogCallback(BaseActivity activity) {
        if (loadingDialog == null && !activity.isFinishing()) {
            loadingDialog = new LoadingDialog(activity);
            loadingDialog.setCancelable(false);
            loadingDialog.setAnimationEnable(true);
            loadingDialog.show();
        }
    }

    @Override
    public void onStart(Request<String, ? extends Request> request) {
        if (loadingDialog != null && !loadingDialog.isShowing()) {
            loadingDialog.show();
        }
    }

    @Override
    public void onFinish() {
        if (loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.dismiss();
        }
    }
}
